package com.znf4.controller.user;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.znf4.base.BaseReturnModel;
import com.znf4.user.address.entity.UserAddress;
import com.znf4.user.address.server.UserAddressServer;

/**
 * 收获地址
 */
@RestController
@RequestMapping("/user/address")
public class UserAddressController {
	
	@Autowired
	private UserAddressServer userAddressServer ;
	

	/**
	 * 函数功能说明 ： 添加收获地址
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> add(UserAddress userAddress, Model model) {
		
		userAddressServer.addUserAddress(userAddress);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	
	
	/**
	 * 函数功能说明 ： 修改收获地址
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> update(UserAddress userAddress, Model model) {
		
		userAddressServer.updateUserAddress(userAddress);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	/**
	 * 函数功能说明 ： 删除收获地址
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delOne(UserAddress userAddress, Model model) {
		
		userAddressServer.delOneUserAddress(userAddress); 
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	/**
	 * 函数功能说明 ： 删除多条收获地址
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delAll(String[]  ids , Model model) {
		
		List<UserAddress> list = new ArrayList<>() ;
		for(int i=0 ; i < ids.length ; i ++ ){
			UserAddress userAddres = new UserAddress() ;
			userAddres.setId(ids[i]);
			list.add(userAddres) ;
		}
		userAddressServer.delAllUserAddress(list);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}
	

	/**
	 * 函数功能说明 ： 获取多个收获地址
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> queryAll(UserAddress userAddress, Model model) {
		
		List<UserAddress> list = userAddressServer.queryAll(userAddress);
		return BaseReturnModel.getMapModel("success", list , "");
	}
	
	

}
